package com.leaf.lowcode.API;

import com.alibaba.fastjson.JSON;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.leaf.lowcode.entity.VisitRecordRequest;
import com.leaf.lowcode.entity.VisitorRequest;

import java.util.HashMap;
import java.util.Map;

public class AppointmentApi {
    /**
     * STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
     */
    static {
        ArtemisConfig.host = "10.140.161.12:443";
        ArtemisConfig.appKey = "29544061"; // 秘钥appkey
        ArtemisConfig.appSecret = "N1Ims5vjYUTQIGdItUjc";
    }
    /**
     * STEP2：设置OpenAPI接口的上下文
     */
    private static final String ARTEMIS_PATH = "/artemis";

    //预约免登记
    public String visitorAppointment(VisitorRequest visitorRequest){
        String url = ARTEMIS_PATH +"/api/visitor/v1/appointment/registration";
        return sendRequest(url, visitorRequest);
    }

    public String getVisitRecords(VisitRecordRequest visitRecordRequest) {
        String url = ARTEMIS_PATH +"/api/visitor/v1/event/turnover/search";
        return sendRequest(url, visitRecordRequest);
    }

    private String sendRequest(String url, Object data) {
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",url);
            }
        };
        String body= JSON.toJSONString(data);
        System.out.println("body"+body);
        return ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
    }

    //访客签离
    public static String out(OutRequest outRequest ){
        String outDataApi = ARTEMIS_PATH +"/api/visitor/v1/visitor/out";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",outDataApi);
            }
        };
        String body=JSON.toJSONString(outRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }


}
